#include "ls_trace_common.h"


char g_szOutput[1024];
char g_u8TraceIndex = 0;
static unsigned char u32logLevel;

void LS_Trace_SetLevel(LOG_LEVEL_E _loglevel)
{
    //定义了realse模式。才能控制日志的级别
	u32logLevel = _loglevel;
}


void LS_Trace(unsigned char loglevel,const char* _szColor, const char* _szPrefix, const char* _szFile, unsigned int _u32Line, const char* _szFunction, const char* _szFmt, ...)
{
    
#ifdef LS_REALSE_COMPLIE
	if (u32logLevel < loglevel) {
	 	 return;
	}
#endif

	char* szBasename = strrchr(_szFile, '/');
	if(szBasename == NULL)
	{
		szBasename = (char*)_szFile;
	}
	else
	{
		szBasename +=1;
	}

    snprintf(g_szOutput,sizeof(g_szOutput),"[%02hhu][%s]>%s%s:%s:%u>",g_u8TraceIndex++,_szPrefix,_szColor,szBasename,_szFunction, _u32Line);

	int u32Using = strlen(g_szOutput);
	va_list argptr;
	va_start(argptr, _szFmt);
	vsnprintf(g_szOutput+u32Using,sizeof(g_szOutput)-u32Using,_szFmt,argptr);
	va_end(argptr);
	u32Using = strlen(g_szOutput);
	g_szOutput[u32Using] = '\n';
	g_szOutput[u32Using+1] = '\r';
	g_szOutput[u32Using+2] = 0;
	printf("%s"LS_NONE,g_szOutput);
}